<template>
  <div id="app">
    <table class="tb">
      <tr>
        <th>欢迎光临vue开发的收银系统——水果店</th>
      </tr>
      <tr>
        <td><b>苹果10￥/斤,折扣是8折</b></td>
      </tr>
      <tr>
        <td>
          请输入您要购买的斤数 &nbsp;<input
            type="text"
            v-model.number.trim="num"
          />
        </td>
      </tr>
      <tr>
        <td><button @click="pay">老板买单~</button></td>
      </tr>
      <tr>
        <td>
          <span>总价是{{ total }}元</span>&nbsp;
          <span>折扣后{{ newMoney }}元</span>&nbsp;
          <span>省了{{ less }}元</span>&nbsp;
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 1,
      price: 10,
      total: 10,
      newMoney: 8,
      less: 2,
    };
  },
  methods: {
    pay() {
      this.total = this.num * this.price;
      this.newMoney = this.total * 0.8;
      this.less = this.total - this.newMoney;
    },
  },
};
</script>

<style>
#app {
  width: 600px;
  margin: 10px auto;
}

.tb {
  border-collapse: collapse;
  width: 100%;
}

.tb th {
  background-color: #0094ff;
  color: white;
}

.tb td,
.tb th {
  padding: 5px;
  border: 1px solid black;
  text-align: center;
}

.add {
  padding: 5px;
  border: 1px solid black;
  margin-bottom: 10px;
}
</style>